package com.wnx.db;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

import com.wnx.entity.Admin;
import com.wnx.entity.Goods;
import com.wnx.entity.Users;
import com.wnx.util.HibernateUtil;

public class UserDao {
	public UserDao(){
		
	}
	public Users UpdateUserByid(Users users){
		Session session = HibernateUtil.getSession();
		Transaction transaction = session.beginTransaction();
		String hql ="update Users set introduce=?,phone=?,email=? where id=?";
		Query query = session.createQuery(hql);
		query.setParameter(0, users.getIntroduce());
		query.setParameter(1, users.getPhone());
		query.setParameter(2, users.getEmail());
		query.setParameter(3, users.getId());
		query.executeUpdate();
		transaction.commit();
        session.close();
		return users;
	}
	public List getUsersAll(int id){
		Session session = new HibernateUtil().getSession();
		Transaction transaction = session.beginTransaction();
		String hql = "from Users where id=?";
		Query<Users> query = session.createQuery(hql,Users.class);
		query.setParameter(0, id);
		List list=query.list();
        transaction.commit();
        session.close();
		return list;
	}
	public Users UpdateUserImgById(Users users){
		Session session = HibernateUtil.getSession();
		Transaction transaction = session.beginTransaction();
		String hql ="update Users set images=? where id=?";
		Query query = session.createQuery(hql);
		query.setParameter(0, users.getImages());
		query.setParameter(1, users.getId());
		query.executeUpdate();
		transaction.commit();
        session.close();
		return users;
	}
}
